// pages/homeTab/mate/mate.js
const app = getApp();
var util = require('../../../../../utils/util.js')
var times = 8;
var timee = 17;
var dur = 1;
const date = new Date();
const hours = [];
const thours = [];
const minutes = ['00', '30'];
//获取小时
for (let i = 0; i < 24; i++) {
  if (i < 10) {
    i = "0" + i;
  }
  hours.push("" + i);
}
for (let i = 0; i < 24; i++) {
  if (i == 0) {
    i = "立即开始";
    thours.push(i);
    i = 0;
    i = "0" + i;
    thours.push("" + i);
    continue;
  } else if (i > 0 && i < 10) {
    i = "0" + i;
  }
  thours.push("" + i);
};

Page({

  /**
   * 页面的初始数据
   */
  data: {
    faceId: '',
    head: '',
    btn: '',
    btn_disabled: false,
    game: ['王者荣耀'],
    inde:'',
    objectGame: [
      {
        id: 0,
        name: '王者荣耀'
      }
    ],
    system: ['IOS', '安卓'],
    objectSystem: [
      {
        id: 0,
        name: 'IOS',
        id: 1,
        name: '安卓'
      }
    ],
    courseType: ['入门教学课', '实战教学课','冲刺班'],
    objectSystem: [
      {
        id: 0,
        name: '入门教学课',
        id: 1,
        name: '实战教学课',
        id: 2,
        name: '冲刺班'
      }
    ],
    platform: ['QQ', '微信'],
    objectPlatform: [
      {
        id: 0,
        name: 'QQ',
        id: 1,
        name: '微信'
      }
    ],
    rank: ['秩序白银', '荣耀黄金', '尊贵铂金', '永恒钻石V','永恒钻石IV-III','永恒钻石II-I','至尊星耀V-III','至尊星耀II-I','王者1-10','王者11-20','王者21-25','王者26-30','王者31-35','王者36-40','王者41-45','王者46-50','王者51-100'],
    objectRank: [
      {
        id: 0,
        name: '秩序白银',
        id: 1,
        name: '荣耀黄金',
        id: 2,
        name: '尊贵铂金',
        id: 3,
        name: '永恒钻石V',
        id: 4,
        name: '永恒钻石Ⅳ-Ⅲ',
        id: 5,
        name: '永恒钻石Ⅱ-Ⅰ',
        id: 6,
        name: '至尊星耀V-Ⅲ',
        id: 7,
        name: '至尊星耀Ⅱ-Ⅰ',
        id: 8,
        name: '最强王者1-10',
        id: 9,
        name: '最强王者11-20',
        id: 10,
        name: '最强王者21-25',
        id: 11,
        name: '最强王者26-30',
        id: 12,
        name: '最强王者31-35',
        id: 13,
        name: '最强王者36-40',
        id: 14,
        name: '最强王者41-45',
        id: 15,
        name: '最强王者46-50',
        id: 16,
        name: '最强王者51-100'
      }
    ],
    duration: ['1小时', '2小时', '3小时', '4小时'],
    objectDuration: [
      {
        id: '0',
        name: '1小时',
        id: '1',
        name: '2小时',
        id: '2',
        name: '3小时',
        id: '3',
        name: '4小时',
      }
    ],
    time: '02:00',
    timeArray: [thours, minutes],
    timeIndex: [3, 0],
    stime: '02:00',
    stimeArray: [thours, minutes],
    stimeIndex: [3, 0],
    etime: '03:00',

    // stime: '08:00',
    // stimeArray: [hours, minutes],
    // stimeIndex: [8, 0],
    // etime: '17:00',
    etimeArray: [hours, minutes],
    etimeIndex: [17, 0],
    // duration: '1小时',
    endtime:'9:00',
    sclass: ['入门教学', '实战教学', '冲刺班'],
    index1: 0,
    index2: 0,
    index3: 0,
    index4: 0,
    index5: 0,
    index6: 0,
    shour: '02',
    sminute: '00',
    avatarUrl: '',
    nickName: [],
    score: '',
    preTime: '',
    courseInfo: '',
    courseType: '',
    coursePr: '',
    shichang:''
  },

  bindGameChange: function (e) {
    this.setData({
      index1: e.detail.value
    })
  },

  bindSystemChange: function (e) {
    this.setData({
      index2: e.detail.value
    })
  },

  bindPlatformChange: function (e) {
    this.setData({
      index3: e.detail.value
    })
  },

  bindRankChange: function (e) {
    this.setData({
      index4: e.detail.value
    })
  },
  bindCourseType: function (e) {
    this.setData({
      index5: e.detail.value
    })
  },
  bindshichang: function (e) {
    this.setData({
      index6: e.detail.value,
    })
    inde=index6;
    this.bindendtimeChange();
    // shichang:index6
  },
  bindStimeChange: function (e) {
    this.setData({
      stimeIndex: e.detail.value
    })
    const index = this.data.stimeIndex;
    if (index[0] == 0) {
      var ttime = util.formatDate(new Date());
      this.setData({
        stime: ttime
      })
      const shour = util.formatHour(new Date());
      const minute = util.formatMinute(new Date());
      this.setData({
        shour: shour,
        sminute: minute
      })
      this.bindEtimeChange();
    } else {
      const hour = this.data.stimeArray[0][index[0]];
      const minute = this.data.stimeArray[1][index[1]];
      this.setData({
        stime: hour + ':' + minute,
        shour: hour,
        sminute: minute
      })
      this.bindEtimeChange();
    }
  },
  bindStimeColumnChange: function (e) {
    var data = {
      stimeArray: this.data.stimeArray,
      stimeIndex: this.data.stimeIndex
    };
    data.stimeIndex[e.detail.column] = e.detail.value;
    this.setData(data);
  },
  bindEtimeChange: function () {
    const index = this.data.stimeIndex;
    if (index[0] == 0) {
      var shour = Number(this.data.shour);
      var ehour = dur + shour;
      var eminute = this.data.sminute;
      this.setData({
        etime: ehour + ':' + eminute
      })
    } else {
      var shour = Number(this.data.shour);
      var ehour = dur + shour;
      var eminute = this.data.sminute;
      if (ehour < 10) {
        ehour = '0' + ehour;
      } else if (ehour >= 24) {
        ehour = ehour - 24;
        ehour = '0' + ehour;
      }
      this.setData({
        etime: ehour + ':' + eminute
      })
    }
  },
  bindEtimeColumnChange: function (e) {
    var data = {
      etimeArray: this.data.etimeArray,
      etimeIndex: this.data.etimeIndex
    };
    data.etimeIndex[e.detail.column] = e.detail.value;
    this.setData(data);
  },

  bindendtimeChange: function () {
    // var endtime = times+index6;
    this.setData({ 
      endtime: times + inde
    })
    console.log(endtime,'enetime')
  },

  bindDurationChange: function (e) {
    this.setData({
      index6: e.detail.value
    })
    var index = Number(this.data.index6);
    dur = index + 1;
    //time = time.toFixed(1);
    this.bindEtimeChange();
  },

  bindSclassChange: function (e) {
    this.setData({
      index5: e.detail.value
    })
  },

  bindMate: function () {
    this.setData({
      btn_mate: submit
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
        etimeStatus: true,
        durationStatus: true,
        sclassStatus: true,
        btn: '开始课程',
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  submit: function () {
    if (dur <= 0) {
      wx.showToast({
        title: '时间错误\r\n请重新选择',
        icon: 'none',
        duration: 2000,
      })
      return;
    }
    const index1 = this.data.index1;
    const index3 = this.data.index3;
    const index2 = this.data.index2;
    const index4 = this.data.index4;
    const index5 = this.data.index5*1+1;
    const index6 = this.data.index6;
    const stime = this.data.stime;
    const etime = this.data.etime
    console.log(index5,'index5')
    var objectSystem = index2*1+1;
    var game = this.data.game[index1];
    var platform = this.data.platform[index3];
    var rank = index4*1+1;
    var duration = parseInt(this.data.duration[index6]);
    console.log(duration,'duration时长')
    app.globalData.system =index2;
    app.globalData.shichang1= duration;
    app.globalData.shichang = stime+'-'+etime;
    app.globalData.levelCode = this.data.rank[rank-1];
    app.globalData.levelCode_code = rank;
    app.globalData.platform = platform;
    app.globalData.gameChoice = game;
    app.globalData.courseType = index5;
    console.log(stime, etime, app.globalData.shichang,'app.globalData.shichang')
    console.log(platform, 'platform')
    console.log(game, 'game')
    console.log(rank, 'rank')
    console.log(objectSystem, 'objectSystem')
    console.log(index5, 'index5')
    wx.request({
      url: 'https://www.enjoyyz.com:8443/yinzuo/start',
      method: 'GET',
      data: {
        levelCode: rank,
        courseType:index5,
        duration: duration,
        userId:app.globalData.teacherid
      },
      header: {
        'content-type': 'application/json'
      },
      success: (res) => {
        const data_num = res.data.length;
        console.log(app.globalData.userid,'app.globalData.userid')
        console.log(res.data.data,'res.data.data');
        app.globalData.searchResult=res.data.data
        console.log(app.globalData.levelCode_code,' app.globalData.levelCode_code ')
      },
    
    });
    wx.navigateTo({
      url: 'payment/payment',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
})